home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / Sample Code / Snippets / QuickDraw / CopyBits vs. CopyMask / Sample.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-02-18  |  9.6 KB  |  241 lines  |  [TEXT/KAHL]

  1. /*------------------------------------------------------------------------------
  2. #
  3. #    Apple Macintosh Developer Technical Support
  4. #
  5. #    MultiFinder-Aware Simple Sample Application
  6. #
  7. #    Sample
  8. #
  9. #    Sample.h    -    Rez and C Include Source
  10. #
  11. #    Copyright © 1989 Apple Computer, Inc.
  12. #    All rights reserved.
  13. #
  14. #    Versions:    
  15. #                1.00                08/88
  16. #                1.01                11/88
  17. #                1.02                04/89
  18. #                1.03                06/89
  19. #                1.04                06/92
  20. #
  21. #    Components:
  22. #                Sample.p            June 1, 1989
  23. #                Sample.c            June 1, 1989
  24. #                SampleInit.c        June 2, 1992
  25. #                Sample.a            June 1, 1989
  26. #                Sample.inc1.a        June 1, 1989
  27. #                SampleMisc.a        June 1, 1989
  28. #                Sample.r            June 1, 1989
  29. #                Sample.h            June 1, 1989
  30. #                PSample.make        June 1, 1989
  31. #                CSample.make        June 1, 1989
  32. #                ASample.make        June 1, 1989
  33. #                CSample.π            June 2, 1992
  34. #                CSample.π.rsrc        June 2, 1992
  35. #
  36. #    Sample is an example application that demonstrates how to
  37. #    initialize the commonly used toolbox managers, operate 
  38. #    successfully under MultiFinder, handle desk accessories, 
  39. #    and create, grow, and zoom windows.
  40. #
  41. #    It does not by any means demonstrate all the techniques 
  42. #    you need for a large application. In particular, Sample 
  43. #    does not cover exception handling, multiple windows/documents, 
  44. #    sophisticated memory management, printing, or undo. All of 
  45. #    these are vital parts of a normal full-sized application.
  46. #
  47. #    This application is an example of the form of a Macintosh 
  48. #    application; it is NOT a template. It is NOT intended to be 
  49. #    used as a foundation for the next world-class, best-selling, 
  50. #    600K application. A stick figure drawing of the human body may 
  51. #    be a good example of the form for a painting, but that does not 
  52. #    mean it should be used as the basis for the next Mona Lisa.
  53. #
  54. #    We recommend that you review this program or TESample before 
  55. #    beginning a new application.
  56. ------------------------------------------------------------------------------*/
  57.  
  58. /* In MPW 3.0 and THINK C we can use actual prototypes for parameter type checking. */
  59. /* Function prototypes for all functions in this program. */
  60.  
  61. #ifndef rez
  62. void EventLoop( void );
  63. void HandleNormalEvent(EventRecord *event);
  64. void HandleDialogEvent(EventRecord *event);
  65. void AdjustCursor( Point mouse, RgnHandle region );
  66. void GetGlobalMouse( Point *mouse );
  67. void DoUpdate( WindowPtr window );
  68. void DoActivate( WindowPtr window, Boolean becomingActive );
  69. void DoContentClick( WindowPtr window );
  70. void DrawWindow( WindowPtr window );
  71. void AdjustMenus( void );
  72. void DoMenuCommand( long menuResult );
  73. void SetLight( WindowPtr window, Boolean newStopped );
  74. Boolean DoCloseWindow( WindowPtr window );
  75. void Terminate( void );
  76. void ForceEnvirons( void );
  77. Boolean IsAppWindow( WindowPtr window );
  78. Boolean IsDAWindow( WindowPtr window );
  79. void AlertUser( void );
  80. void Initialize( void );
  81. Boolean GoGetRect( short rectID, Rect *theRect );
  82. Boolean TrapAvailable( short tNumber, TrapType tType );
  83.  
  84. void LetTheGameBegin(DialogPtr srcDialogP);
  85. #endif
  86.  
  87. /*    These #defines correspond to values defined in the Pascal source code.
  88.     Sample.c and Sample.r include this file. */
  89.  
  90. /*    Determining an application's minimum size to request from MultiFinder depends
  91.     on many things, each of which can be unique to an application's function,
  92.     the anticipated environment, the developer's attitude of what constitutes
  93.     reasonable functionality and performance, etc. Here is a list of some things to
  94.     consider when determining the minimum size (and preferred size) for your
  95.     application. The list is pretty much in order of importance, but by no means
  96.     complete.
  97.     
  98.     1.    What is the minimum size needed to give almost 100 percent assurance
  99.         that the application won't crash because it ran out of memory? This
  100.         includes not only things that you do have direct control over such as
  101.         checking for NIL handles and pointers, but also things that some
  102.         feel are not so much under their control such as QuickDraw and the
  103.         Segment Loader.
  104.         
  105.     2.    What kind of performance can a user expect from the application when
  106.         it is running in the minimum memory configuration? Performance includes
  107.         not only speed in handling data, but also things like how many documents
  108.         can be opened, etc.
  109.         
  110.     3.    What are the typical sizes of scraps [is a boy dog] that a user might
  111.         wish to work with when lauching or switching to your application? If
  112.         the amount of memory is too small, the scrap may get lost [will have
  113.         to be shot]. This can be quite frustrating to the user.
  114.         
  115.     4.    The previous items have concentrated on topics that tend to cause an
  116.         increase in the minimum size to request from MultiFinder. On the flip
  117.         side, however, should be the consideration of what environments the
  118.         application may be running in. There may be a high probability that
  119.         many users with relatively small memory configurations will want to
  120.         avail themselves of your application. Or, many users might want to use it
  121.         while several other, possibly related/complementary applications are
  122.         running. If that is the case, it would be helpful to have a fairly
  123.         small minimum size.
  124.     
  125.     So, what did we decide on Sample? First, Sample has little risk of
  126.     running out of memory once it starts. Second, performance isn't much
  127.     of an issue since it doesn't do much and multiple windows are not
  128.     allowed. Third, there are no edit operations in Sample itself, so we
  129.     just want to provide enough space for a reasonable scrap to survive
  130.     between desk accessory launches. Lastly, Sample should intrude as little
  131.     as possible, so the effort should be towards making it as small as possible.
  132.     We looked at some heap dumps while the application was running under
  133.     various partition sizes. With a size of 23K, there was approximately
  134.     8-9K free, which is a good 'slop' factor in an application like this
  135.     which doesn't do much, but where we'd still like the scrap to survive
  136.     most of the time. */
  137.  
  138. #define kMinSize    23                /* application's minimum size (in K) */
  139.  
  140. /*    We made the preferred size bigger than the minimum size by 12K, so that
  141.     there would be even more room for the scrap, FKEYs, etc. */
  142.  
  143. #define kPrefSize    35                /* application's preferred size (in K) */
  144.  
  145. #define    rMenuBar    128                /* application's menu bar */
  146. #define    rAboutAlert    128                /* about alert */
  147. #define    rUserAlert    129                /* error user alert */
  148. #define    rWindow        1000            /* application's window */
  149. #define rStopRect    128                /* rectangle for Stop light */
  150. #define rGoRect        129                /* rectangle for Go light */
  151.  
  152. /* kSysEnvironsVersion is passed to SysEnvirons to tell it which version of the
  153.    SysEnvRec we understand. */
  154.  
  155. #define    kSysEnvironsVersion        1
  156.  
  157. /* kOSEvent is the event number of the suspend/resume and mouse-moved events sent
  158.    by MultiFinder. Once we determine that an event is an osEvent, we look at the
  159.    high byte of the message sent to determine which kind it is. To differentiate
  160.    suspend and resume events we check the resumeMask bit. */
  161.  
  162. #define    kOSEvent                app4Evt    /* event used by MultiFinder */
  163. #define    kSuspendResumeMessage    1        /* high byte of suspend/resume event message */
  164. #define    kResumeMask                1        /* bit of message field for resume vs. suspend */
  165. #define    kMouseMovedMessage        0xFA    /* high byte of mouse-moved event message */
  166. #define    kNoEvents                0        /* no events mask */
  167.  
  168. /* The following constants are used to identify menus and their items. The menu IDs
  169.    have an "m" prefix and the item numbers within each menu have an "i" prefix. */
  170.  
  171. #define    mApple                    128        /* Apple menu */
  172. #define    iAbout                    1
  173.  
  174. #define    mFile                    129        /* File menu */
  175. #define    iNew                    1
  176. #define    iClose                    4
  177. #define    iQuit                    12
  178.  
  179. #define    mEdit                    130        /* Edit menu */
  180. #define    iUndo                    1
  181. #define    iCut                    3
  182. #define    iCopy                    4
  183. #define    iPaste                    5
  184. #define    iClear                    6
  185.  
  186. #define    mLight                    131        /* Light menu */
  187. #define    iStop                    1
  188. #define    iGo                        2
  189.  
  190.  
  191. // dialog item constants
  192. #define kReadySetGoButton        17
  193.  
  194. /*    1.01 - kTopLeft - This is for positioning the Disk Initialization dialogs. */
  195.  
  196. #define kDITop                    0x0050
  197. #define kDILeft                    0x0070
  198.  
  199. /*    1.01 - kMinHeap - This is the minimum result from the following
  200.     equation:
  201.         
  202.         ORD(GetApplLimit) - ORD(ApplicZone)
  203.         
  204.     for the application to run. It will insure that enough memory will
  205.     be around for reasonable-sized scraps, FKEYs, etc. to exist with the
  206.     application, and still give the application some 'breathing room'.
  207.     To derive this number, we ran under a MultiFinder partition that was
  208.     our requested minimum size, as given in the 'SIZE' resource. */
  209.      
  210. #define kMinHeap                21 * 1024
  211.     
  212. /*    1.01 - kMinSpace - This is the minimum result from PurgeSpace, when called
  213.     at initialization time, for the application to run. This number acts
  214.     as a double-check to insure that there really is enough memory for the
  215.     application to run, including what has been taken up already by
  216.     pre-loaded resources, the scrap, code, and other sundry memory blocks. */
  217.      
  218. #define kMinSpace                8 * 1024
  219.  
  220. /* kExtremeNeg and kExtremePos are used to set up wide open rectangles and regions. */
  221.  
  222. #define kExtremeNeg                -32768
  223. #define kExtremePos                32767 - 1 /* required to address an old region bug */
  224.  
  225. /* these #defines are used to set enable/disable flags of a menu */
  226.  
  227. #define AllItems    0b1111111111111111111111111111111    /* 31 flags */
  228. #define NoItems        0b0000000000000000000000000000000
  229. #define MenuItem1    0b0000000000000000000000000000001
  230. #define MenuItem2    0b0000000000000000000000000000010
  231. #define MenuItem3    0b0000000000000000000000000000100
  232. #define MenuItem4    0b0000000000000000000000000001000
  233. #define MenuItem5    0b0000000000000000000000000010000
  234. #define MenuItem6    0b0000000000000000000000000100000
  235. #define MenuItem7    0b0000000000000000000000001000000
  236. #define MenuItem8    0b0000000000000000000000010000000
  237. #define MenuItem9    0b0000000000000000000000100000000
  238. #define MenuItem10    0b0000000000000000000001000000000
  239. #define MenuItem11    0b0000000000000000000010000000000
  240. #define MenuItem12    0b0000000000000000000100000000000
  241.